<template>
  <div id="nav">
    <router-link class="tab-bar-item" to="/home">
      <div class="icon">
        <i class="iconfont icon-biaoqianA01_shouye-76"></i>
      </div>
      <div>首页</div>
    </router-link>
    <router-link to="/category" class="tab-bar-item"
      ><div class="icon">
        <i class="iconfont icon-fenlei"></i>
      </div>
      <div>分类</div></router-link
    >
    <router-link to="/shopcart" class="tab-bar-item"
      ><div class="icon">
        <!-- 这里购物车图标数量就是store中的state -->
        <van-badge :content="$store.state.cartCount" max="9">
          <i class="iconfont icon-tubiaolunkuo-"></i>
        </van-badge>
      </div>
      <div>购物车</div></router-link
    >
    <router-link to="/profile" class="tab-bar-item"
      ><div class="icon">
        <i class="iconfont icon-80gerenzhongxin"></i>
      </div>
      <div>我的</div></router-link
    >
  </div>
  <router-view />
</template>

<script>
import { Badge } from "vant";
import { useStore } from "vuex";
import { onMounted } from "vue";
export default {
  name: "App",
  setup() {
    const store = useStore();
    // 这里是因为页面刷新 state会重置，所以在这每次挂载之后都获取购物车数量
    onMounted(() => {
      store.dispatch("updateCart");
    });
  },
  components: {
    [Badge.name]: Badge,
  },
};
</script>

<style lang="less">
@import "@/assets/css/base.less";
@import "@/assets/css/iconfont.css";

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  background-color: #f6f6f6;
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  box-shadow: 0 -3px 1px rgba(100, 100, 100, 0.1);

  z-index: 20;

  a {
    &.router-link-exact-active {
      color: #42b983;
    }
  }

  .tab-bar-item {
    flex: 1;
    text-align: center;
    height: 50px;
    font-size: @font-size;
  }
  .tab-bar-item .icon {
    width: 24px;
    height: 24px;
    margin-top: 5px;
    vertical-align: middle;
    display: inline-block;
  }
}
</style>
